<style>
    .tag{
        display: inline-block;
        margin-right: 10px;
        padding: 5px 10px;
        border: 1px solid #ccc;
        cursor: pointer;
    }
    .select{
        background-color: #f89406;
        color: #fff;
    }
</style>
<script class="resources library" src="/statics/js/area.js" type="text/javascript"></script>

<div class="container-fluid" style="padding: 20px 10px 0px 10px">
	<div class="row-fluid">
		<div class="well">
		    <ul class="nav nav-tabs">
		      <li class="active"><b>医院设置</b></li>
		    </ul>
		    <div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="home">
					<form id="formid" action="/hospital/addHospt" method="post">
						<p>医院名称：<input type="text" value="<?=$getData['hos_name']?>" name="hos_name" style="width:326px" type='text' class=""></p>
						<p>主体编码：<input type="text" value="<?=$getData['main_code']?>" name="main_code" style="width:326px" ></p>
						<p><div id="setImd" style="display:inline">医院logo：<input type="text" name="logo" class="setImdText" style="width:327px" value="<?=$getData['logo']?>" readonly> <input type="button" class="btn btn-info setImdBtn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['logo'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['logo'] ? transUrl($getData['logo']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
						<p style="margin-left: 13px;">联系人：<input type="text" value="<?=$getData['contact_person']?>" name="name" style="width:326px" ></p>
						<p>邮箱号码：<input type="text" value="<?=$getData['email']?>" name="email" style="width:326px" ></p>
						<p>联系号码：<input type="text" value="<?=$getData['mobile']?>" name="mobile" style="width:326px" ></p>
						<p>营业执照登记号：<input type="text" value="<?=$getData['agency_number']?>" name="agency_number" style="width:285px" ></p>
						<p>机构类型：
							<select name="hos_type" id="">
								<option value="">请选择</option>
							</select>
						</p>
						<span>医院地区：<select id="s_province" name="s_province" class="needval" style="width:162px;"></select>
		                <select id="s_city" name="s_city" class="needval" style="width:162px;"></select>  
		                <!--<select id="s_county" name="s_county" class="needval" style="width:163px;"></select>  -->
  						<script type="text/javascript">_init_area();</script><br/>
                        <p class="con">机构简介: <textarea style="width:575px;height:310px;margin-left:73px;margin-top:0" name="hospt_detail"><?=htmlspecialchars_decode($getData['hospt_detail'])?></textarea></p>
						<input type="hidden" value="1" name="dosubmit" />
						<input type="hidden" value="<?=$getData['id']?>" name="id" />
					</form>
				</div>
				<div class="btn-toolbar">
				    <button class="btn btn-primary" id="btn-save" style="margin-left:72px;margin-top:20px"><i class="icon-save"></i> 保存</button>
				  <div class="btn-group">
				  </div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=d7IG6wfuKy6EkfAvka9rm1GGztEE4GBO"></script> -->
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=acc0dfea7300a43ee75a20cb8122d5ef"></script>
<script>
	$(window).load(function(){
		$('#s_province').val("<?=$getData['province']?>");
		$('#s_province').change(function(){
			setTimeout(function(){
				$('#s_city').val("<?=$getData['city']?>");
				$('#s_city').change(function(){
					setTimeout(function(){$('#s_county').val("<?=$getData['area']?>");},100);
				}).trigger('change');
			},100);
		}).trigger('change');
	})
</script>
<script>
$(function(){

	$('.setImdBtn').click(function(){
		$('#setImd').selfups();
	});

	$('#btn-save').click(function(){
		if($('input[name="hos_name"]').val() == ''){
			showmsg('机构名称不能为空！');
		}else if($('input[name="main_code"]').val() == ''){
			showmsg('机构编码不能为空！');
		}else if($('input[name="logo"]').val() == ''){
			showmsg('机构logo不能为空！');
		}else if($('input[name="name"]').val() == ''){
			showmsg('联系人不能为空！');
		}else if($('input[name="agency_number"]').val() == ''){
			showmsg('营业执照登记号不能为空！');
		}else if($('input[name="hos_type"]:selected').val() == ''){
			showmsg('机构类型不能为空！');
		}else if($('#s_province').val() == '省份' || $('#s_city').val() == '地级市'){
			showmsg('省份城市选择有误');
		}else{
			setBtn($('#btn-save'));
			$('#formid').submit();
		}
	});



	// $('input[name=hospt_addr]').change(function(){
	// 	addr = $(this).val();
	// 	$.ajax({
	// 		url: '/hospital/getLal',
	// 		type: 'POST',
	// 		dataType: 'json',
	// 		data: {'addr': addr},
	// 	})
	// 	.done(function(d) {
	// 		if(d.code == 0){
	// 			$('input[name=longitude]').val(d.result.lng);
	// 			$('input[name=latitude]').val(d.result.lat);
	// 		}else{
	// 			showmsg('获取经纬度失败，请输入正确地址');
	// 			return false;
	// 		}
	// 	})
	// 	.fail(function() {
	// 		console.log("error");
	// 	})		
	// })

	$('input[name=hospt_addr]').change(function(){
		val = $(this).val();
		AMap.service('AMap.Geocoder',function(){//回调函数
		    //实例化Geocoder
		    geocoder = new AMap.Geocoder({
		        city: val//城市，默认：“全国”
		    });
		    //TODO: 使用geocoder 对象完成相关功能
			geocoder.getLocation(val, function(status, result) {
			    if (status == 'complete' && result.info == 'OK') {
			    	arr = result.geocodes[0].location.toString().split(',');
			        $('input[name=longitude]').val(arr[0]);
			        $('input[name=latitude]').val(arr[1]);
			    }else{
			        alert('获取经纬度失败');
			    }
			});
		});
	})
})
</script>